#!/usr/bin/env python
#coding=utf-8

from apscheduler.schedulers.background import BackgroundScheduler
import Logger_Class
import time
import Util


def test(token):
    print(token)
#-----------------------------
# main函数
#-----------------------------
if __name__ == '__main__':
    logger = Logger_Class.Logger_test(logname='D:/log1.txt', loglevel='1', logger="fox").getlog()

    logger.debug('使用scheduler模块设置自动任务的时间')
    #scheduler = BlockingScheduler()#阻塞方式
    scheduler = BackgroundScheduler()
    #更新token自动任务
    scheduler.add_job(Util.updateToken, 'interval', seconds=7200)
    #执行定期巡检自动任务
    scheduler.add_job(Util.send_message, 'interval', seconds=40)
    #开始执行
    scheduler.start()
    try:
        # This is here to simulate application activity (which keeps the main thread alive).
        while True:
            time.sleep(2)    #其他任务是独立的线程执行
            print('sleep!')
    except (KeyboardInterrupt, SystemExit):
        # Not strictly necessary if daemonic mode is enabled but should be done if possible
        scheduler.shutdown()
        print('Exit The Job!')







